package gui;

import gameBasicElements.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author Wojciech Łopata
 *
 */

public class BoardSelectionPanel extends JPanel
{
	private static final long serialVersionUID = -3202964815213975339L;
	private final ButtonGroup group;
	private JComboBox sizeBox;
	
	private BoardType selectedBoardType;
	
	private class CustomActionListener implements ActionListener
	{
		private final BoardType boardType;
		public CustomActionListener(BoardType boardType)
		{
			this.boardType = boardType;
		}
		@Override
		public void actionPerformed(ActionEvent arg0)
		{
			selectedBoardType = boardType;
		}
		
	}
	
	public BoardSelectionPanel()
	{
		group = new ButtonGroup();
		setLayout(new GridLayout(0, 1));
		add(new JLabel("Goban:"));
		for(int i = 0; i < BoardType.values().length; ++i)
		{	
			JRadioButton box = new JRadioButton(BoardType.values()[i].toString(), false);
			box.addActionListener(new CustomActionListener(BoardType.values()[i]));
			if(BoardType.values()[i].equals(BoardType.getDefaultBoard()))
				box.setSelected(true);
			group.add(box);
			add(box);
		}
		selectedBoardType = BoardType.getDefaultBoard();
		sizeBox = new JComboBox(new Integer [] {5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25} );
		sizeBox.setSelectedIndex(7);
		
		JPanel sizeSelection = new JPanel();
		sizeSelection.setLayout(new FlowLayout());
		sizeSelection.add(new JLabel("Rozmiar:"));
		sizeSelection.add(sizeBox);
		add(sizeSelection);
	}
	
	public Board getChoosenBoard()
	{
		return selectedBoardType.makeEmptyBoard((Integer) sizeBox.getSelectedItem());
	}
}
